package com.youth.youthservice.controller;


import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.youth.commonutils.R;
import com.youth.servicebase.exceptionhandler.GlobalException;
import com.youth.youthservice.client.VodClient;
import com.youth.youthservice.entity.EduChapter;
import com.youth.youthservice.entity.EduVideo;
import com.youth.youthservice.service.EduVideoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;

/**
 * <p>
 * 课程视频 前端控制器
 * </p>
 *
 * @author CM
 * @since 2023-4-30
 */
@Api(description = "课程章节里面的小结")
@RestController
@RequestMapping("/eduservice/video")
//使用nginx是需要使用@CrossOrigin解决跨域问题的，现在使用gateway网关替代   /*解决跨域问题*/
public class EduVideoController {

    @Autowired
    private EduVideoService videoService;

    @ApiOperation("为课程章节添加小节")
    @PostMapping("insertVideo")
    public R insertVideoForChapter(@RequestBody EduVideo video){
        return videoService.insert(video);
    }

    @ApiOperation("编辑课程大纲时回显章节小节")
    @GetMapping("getVideoInfo/{id}")
    public R getVideoInfoById(@PathVariable("id") String id){
        return R.ok().data("eduVideo",videoService.getById(id));
    }

    @ApiOperation("更新章节小节信息")
    @PostMapping("updateVideo")
    public R updateChapterById(@RequestBody EduVideo eduVideo){
        videoService.updateById(eduVideo);
        return R.ok();
    }

    @ApiOperation("删除视频后更新小节信息")
    @PostMapping("updateSourceVideo/{id}")
    public R updateSourceVideo(@PathVariable("id") String id){
        return videoService.updateSourceVideo(id);
    }


    @ApiOperation("删除小节")
    @DeleteMapping("{id}")
    public R deleteVideoById(@PathVariable("id") String VideoId){
        return videoService.removeVideo(VideoId);
    }



    @GetMapping("getVideo/{videoId}")
    public R getVideoAsc(@PathVariable("videoId") String videoId) {
        return videoService.getVideoAsc(videoId);
    }


    @GetMapping("getPlayUrl/{videoId}")
    public R getPlayUrl(@PathVariable("videoId") String videoId){
        return videoService.getPlayUrl(videoId);
    }



}

